class Solution:
    def equalSubstring(self, s: str, t: str, maxCost: int) -> int:
        res = 0
        left = 0
        right = 0
        balance = maxCost
        while right < len(s):
            balance -= abs(ord(s[right]) - ord(t[right]))
            while balance < 0:
                balance += abs(ord(s[left]) - ord(t[left]))
                left += 1
            res = max(res, right - left + 1)
            right += 1

        return res
